package com.ubb.dbms.domain.queryResult;

import java.util.HashMap;
import java.util.Map;

import com.ubb.dbms.domain.queryData.Condition;

public class SelectedRow {
	
	/**
	 * Contains a single select row values.
	 * Map<Column name, Row value>
	 */
	private Map<String, Object> rowValues;
	
	public SelectedRow() {
		rowValues = new HashMap<String, Object>();
	}
	
	public Map<String, Object> getRowValues() {
		return rowValues;
	}

	public void setRowValues(Map<String, Object> rowValues) {
		this.rowValues = rowValues;
	}

	public void addRowValue(String columnName, Object rowValue) {
		rowValues.put(columnName, rowValue);
	}
	
	public Object getRowValue(String columnName) {
		return rowValues.get(columnName);
	}
	
	public boolean checkCondition(Condition condition) {
		String columnName = condition.getLeftOperand().toString();
		Object substitutedLeftOperand = this.getRowValue(columnName);
		
		Condition conditionToEvaluate = new Condition();
		conditionToEvaluate.setLeftOperand(substitutedLeftOperand);
		conditionToEvaluate.setOperator(condition.getOperator());
		conditionToEvaluate.setRightOperand(condition.getRightOperand());
		
		return conditionToEvaluate.evaluate();
	}
}
